import React, { Component } from 'react';
import {
    Button,
    View,
    Text,
} from 'react-native'

class DetailScreen extends Component {
  state={count:0};
  static navigationOptions= (props) =>{
    const params = props.navigation.state.params;
    return {
      title:'Details页',
      headerRight: (                        //通过params为按钮绑定increase方法
        <Button onPress={params.increase} title='+1' />
      ),
    }
  };

  componentWillMount() {                    //通过setParams将increase方法绑定到_increase
    this.props.navigation.setParams({ increase: this._increase });
  }
  _increase=()=>{                           //设置state.count+1
    this.setState(preState=>{return {count:preState.count+1}});
  };

  render() {
      return (
          <View>
              <Text>计数为：{this.state.count}</Text>
          </View>
      )
  }
}

export default DetailScreen;
